using Microsoft.AspNetCore.Mvc;
using JTZY.Model.Business.Dto;
using JTZY.Model.Business;
using JTZY.Service.Business.IBusinessService;
using JTZY.Admin.WebApi.Filters;

//创建时间：2024-12-01
namespace JTZY.Admin.WebApi.Controllers.Business
{
    /// <summary>
    /// 代理商表
    /// </summary>
    [Verify]
    [Route("business/agent")]
    public class CorecmsagentController : BaseController
    {
        /// <summary>
        /// 代理商表接口
        /// </summary>
        private readonly ICorecmsagentService _CorecmsagentService;

        public CorecmsagentController(ICorecmsagentService CorecmsagentService)
        {
            _CorecmsagentService = CorecmsagentService;
        }

        /// <summary>
        /// 查询代理商表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "corecmsagent:list")]
        public IActionResult QueryCorecmsagent([FromQuery] CorecmsagentQueryDto parm)
        {
            var response = _CorecmsagentService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询代理商表详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "corecmsagent:query")]
        public IActionResult GetCorecmsagent(int Id)
        {
            var response = _CorecmsagentService.GetInfo(Id);
            
            var info = response.Adapt<CorecmsagentDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加代理商表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "corecmsagent:add")]
        [Log(Title = "代理商表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddCorecmsagent([FromBody] CorecmsagentDto parm)
        {
            var modal = parm.Adapt<Corecmsagent>().ToCreate(HttpContext);

            var response = _CorecmsagentService.AddCorecmsagent(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新代理商表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "corecmsagent:edit")]
        [Log(Title = "代理商表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateCorecmsagent([FromBody] CorecmsagentDto parm)
        {
            var modal = parm.Adapt<Corecmsagent>().ToUpdate(HttpContext);
            var response = _CorecmsagentService.UpdateCorecmsagent(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除代理商表
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete/{ids}")]
        [ActionPermissionFilter(Permission = "corecmsagent:delete")]
        [Log(Title = "代理商表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteCorecmsagent([FromRoute]string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_CorecmsagentService.Delete(idArr));
        }

    }
}